<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/fr_style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
		
		 <script type="text/javascript" src="./libs/spark-md5-3.0.0.min.js"></script>
	    <script type="text/javascript" src="./libs/crypto-js.js"></script>
	    <script type="text/javascript" src="./libs/base64.min.js"></script>
	    <script type="text/javascript" src="./libs/ufile-token.js"></script>
		<style>
	    	input.picInput{
	    		display: none;
	    	}
	    	img.picShow{
	    		width:80px;
	    		height:80px;
	    	}
	    	.many{
	    		position:relative;
	    		display: inline-block;
	    		margin-right:20px;
	    		width:80px;
	    		height:80px;
	    	}
	    	.many img{
	    		width:80px;
	    		height:80px;
	    	}
	    	.many span{
	    		position:absolute;
	    		width:15px;
	    		height:15px;
	    		top:0;
	    		right:0;
	    		background: url(img/del.png);
	    		background-size: 15px 15px;
	    	}
	    	.toolong{
	    		display: block;
	    		max-width:200px;
	    	}
	    </style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>游戏用户</a>
						</li>
						<li class="active">轮播图列表</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							轮播图列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="add()"><i class="fa fa-plus" ></i>&nbsp;添加</button>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>id</th>
												<th>图片</th>
												<th>跳转地址</th>
												<th>添加时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		<div class="modal fade parents in" id="addbannerModal" >
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> 
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
						<h4 class="modal-title">添加产品轮播图</h4> </div>
					<div class="modal-body">
						<div class="row">
							<label class="margin-bottom-none col-xs-12">跳转链接<input type="text" class="form-control" name="jump_url"></label>
							<div class="margin-bottom-none col-xs-12">
								<div>展示图片</div>
								<label style="display: inline-block;">
									<input type="file" class="form-control onePic picInput" name="img_url"/>
									<img src="img/add.png" class="picShow" alt="" />
								</label>
							</div>
						</div>
					</div>
					<div class="modal-footer"><button type="button" class="btn btn-primary save" onclick="addSave()">确定</button></div>
				</div>
			</div>
		</div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>

		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<script type="text/javascript">
			var ufile =  new UCloudUFile(bucketName, bucketUrl, tokenPublicKey, tokenPrivateKey, tokenServerUrl, prefix);

			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_ProductViewPager",
					"contentType": "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var Json = {};//renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.length;
							json.recordsFiltered = datajson.data.length;
							json.data = datajson.data;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: null,render:function(data){
							return '<img src='+bucketUrl+data.img_url+' style="width:100px;height:auto;">'
						}//'img_url'
					},
					{
						data: 'jump_url'
					},
					{
						data: 'add_time'
					},
					{
						data: null,
						render: function(data) {
							var str = "<input type='hidden' value='" + JSON.stringify(data) + "'>"; //+ check;
							
							return str+'<button type="button" class="btn btn-danger button-margin" onclick="del(this)" id=""><i class="fa fa-trash-o"></i>&nbsp;&nbsp;删除</button>';
						}
					}
				]
			})
		</script>
		<script type="text/javascript">

			function add(_this) {
				//var data = JSON.parse($(_this).siblings('input').val())
				$("#addbannerModal").modal('show')

			}
			
			function addSave(){
				$.ajax({
					type: "post",
					url: url + "Back_ViewPageAdd",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({ //昵称
							img_url: strSplitUrl($("#addbannerModal [name=img_url]").siblings("img").attr("src")),
							jump_url: $("#addbannerModal [name=jump_url]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#addbannerModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}
			
			function delSave() {
				$.ajax({
					type: "post",
					url: url + "Back_ViewPageDel",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({ //昵称
							id: $("#delModal [name=id]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#delModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function del(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "del",
					title: "删除",
					arg: {
						id: data.id,
						name: data.jump_url
					}
				};
				deleteModal(deleteJson, 'delSave');
			}
			
			
			
			
			$(".onePic").change(function(){
				var date = new Date()
	            var fileRename = localStorage.getItem("wallet_name") + date.valueOf();
	            var file = $(this)[0].files[0];
	            var that = $(this)
	            var data = {
	                file: file,
	                fileRename: fileRename
	            };
				var errorCallBack = function(res) {
	                 console.log(res)
	            };
	            var successCallBack = function(res) {
	                console.log(res)
	                console.log(that)
	                that.siblings('img').attr("src",bucketUrl+fileRename)
	            };
	            var progressCallBack = function(res) {};
	
	            ufile.uploadFile(data, successCallBack, errorCallBack, progressCallBack);
			})
		</script>
	</body>

</html>